/*
 * @Author: QUAN
 * @Date: 2021-10-13 16:15:32
 * @LastEditTime: 2021-10-13 18:19:25
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \mutong-dis\src\utils\permission.js
 */
import store from '@/store';
// 这里得晚点再去获取
let permission = {}
setTimeout(() => {
  permission = store.getters.$permission;
}, 1000);

export default (Vue) => {
  /**自定义按钮权限指令 */
  Vue.directive('permission', {
    mounted(el, binding) {
      //获取按钮权限
      if (!Vue.config.globalProperties.$_has(binding.value[0])) {
        //移除不匹配的按钮
        el.parentNode.removeChild(el);
      }
    },
  });

  //检查权限方法
  Vue.config.globalProperties.$_has = function (value) {
    let isExist = false;

    var btnPermsArr = permission; //获取从服务器请求存储本地的按钮权限
    if (btnPermsArr.includes(value)) {
      isExist = true;
    }
    return isExist;
  };
};